//
//  StatusForwardTableViewCell.swift
//  SinaWeibo
//
//  Created by 胡阳 on 16/6/1.
//  Copyright © 2016年 young4ever. All rights reserved.
//

import UIKit

class StatusForwardTableViewCell: StatusTableViewCell {
    
    // 重写父类属性的didSet并不会覆盖父类的操作
    // 只需要在重写方法中, 做自己想做的事即可
    // 注意点: 如果父类是didSet, 那么子类重写也只能重写didSet
    override var model: Status? {
        
        didSet {
            
            let name = model?.retweeted_status?.user?.name ?? ""
            let text = model?.retweeted_status?.text ?? ""
            
            forwardLabel.text = "@" + name + ":  " + text
        }
    }
    
    override func setupSubViews() {
        super.setupSubViews()
        
        // 1.添加子控件
        contentView.insertSubview(forwardBgView, belowSubview: pictureView)
        contentView.insertSubview(forwardLabel, aboveSubview: forwardBgView)
        
        // 2.布局子控件
        forwardBgView.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -10, y: 10))
        
        forwardBgView.xmg_AlignVertical(type: XMG_AlignType.TopRight, referView: footerView, size: nil)
        
        forwardLabel.xmg_AlignInner(type: XMG_AlignType.TopLeft, referView: forwardBgView, size: nil, offset: CGPoint(x: 10, y: 10))
        
        let cons = pictureView.xmg_AlignVertical(type: .BottomLeft, referView: forwardLabel, size: CGSizeZero, offset: CGPoint(x: 0, y: 10)) 
        
        pictureHeightCons = pictureView.xmg_Constraint(cons, attribute: .Height)
        pictureWidthCons = pictureView.xmg_Constraint(cons, attribute: .Width)
        pictureTopCons = pictureView.xmg_Constraint(cons, attribute: .Top)
    }

    private lazy var forwardLabel : UILabel = {
        let lb = UILabel.fastCreateLabel(UIColor.darkGrayColor(), fontSize: 14)
        lb.numberOfLines = 0
        lb.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 20
        return lb
    }()

    private lazy var forwardBgView : UIButton = {
    
        let btn = UIButton(type: .Custom)
        btn.backgroundColor = UIColor(white: 0.9, alpha: 0.5)
        return btn
    }()
}
